package UDPpractice;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class receiveMassage {
    public static void main(String[] args) throws IOException {
        // 找快递公司
        DatagramSocket ds = new DatagramSocket(10086);

        while (true) {
            // 解压缩货物
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
            ds.receive(dp);

            // 得到货物
            byte[] data = dp.getData();
            int len = dp.getLength();
            String ip = dp.getAddress().getHostAddress();
            String name = dp.getAddress().getHostName();
            System.out.println("ip为：" + ip + ",主机名为：" + name + "的人，发送了数据："
                    + new String(data,0,len));
        }

    }
}
